package se.webbzon.boltzmann.editor.component.sequence;

import java.awt.Component;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JList;
import javax.swing.ListCellRenderer;

import se.webbzon.boltzmann.editor.list.EditorListCell;
import se.webbzon.boltzmann.game.sequence.builder.AbstractSequenceRow;

public class SequenceRowListCell extends EditorListCell implements ListCellRenderer<AbstractSequenceRow> {
	
	// Auto generated serial version UID
	private static final long serialVersionUID = 2720331986969154083L;
	
	// The sequence row associated with this list cell
	private AbstractSequenceRow row;
	
	/*============================================================
	Constructors
	============================================================*/

	/** Creates a new sequence row list cell. **/
	public SequenceRowListCell() {
		super(new Dimension(128,20));
	}
	
	/*============================================================
	Public Methods
	============================================================*/
	
	@Override public void paintComponent(Graphics g) {
		super.paintComponent(g);
		g.setFont(getFont());
		String text;
		if (row == null)
			text = "No row (null)";
		else
			text = row.toString();
		g.drawString(text, 2, 16);
		
	}

	@Override public Component getListCellRendererComponent(
					JList<? extends AbstractSequenceRow> list,
					AbstractSequenceRow row, int index, 
					boolean isSelected, boolean cellHasFocus) {
		setSelected(isSelected);
		this.row = row;
		return this;
	}
	
}
